package testjvm.testclassloader02;

public class TestClassUnLoad {

    // 运行的时候配置VM参数: -verbose:class；用于查看 class 的加载与卸载情况
    // 可以看到：
    //      [Loaded testjvm.testclassloader02.A from file:/C:/Users/xxyzz/IdeaProjects/Java-Learning/06-demo/target/classes/]
    //      [Unloading class testjvm.testclassloader02.A 0x00000007c0061028]
    public static void main(String[] args) throws Exception {
        SimpleURLClassLoader loader = new SimpleURLClassLoader();
        // 用自定义的加载器加载 A
        Class clazzA = loader.load("testjvm.testclassloader02.A");
        Object a = clazzA.newInstance();
        // 清除相关引用
        a = null;
        clazzA = null;
        loader = null;
        // 执行一次 gc 垃圾回收
        System.gc();
        System.out.println("GC over");
    }
}
